package cn.hfatec.shms.web.yk.ykTjcb.service;

import java.util.List;
import java.util.HashMap;


import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.web.yk.ykTjcb.model.YkTjcb;
import cn.hfatec.shms.web.yk.ykTjcb.dao.YkTjcbDao;
import cn.hfatec.shms.web.yk.ykTjcb.model.YkTjcbParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("YkTjcbService")
public class YkTjcbService {

    public static final String BEAN_ID = "YkTjcbService";

    //注入Dao层
    @Resource(name = "YkTjcbDao")
    private YkTjcbDao ykTjcbDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param ykTjcbParams
     * @param page
     *
     */
    @Transactional
    public Table queryYkTjcbTable(YkTjcbParams ykTjcbParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", ykTjcbParams);
        return baseDao.queryTableByPage("queryYkTjcb", params, page);
    }

    /**
     *
     * 插入数据
     * @param ykTjcb
     *
     */
    @Transactional
    public void saveYkTjcb(YkTjcb ykTjcb) {
        if(ykTjcb.getId() != null) {
            YkTjcb result = getYkTjcb(ykTjcb.getId());
            if(result != null) {
                ykTjcbDao.update(ykTjcb);
            } else {
                ykTjcbDao.insert(ykTjcb);
            }
        } else {
            ykTjcbDao.insert(ykTjcb);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    public void deleteYkTjcb(Integer id) {

        ykTjcbDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param ykTjcbList
     *
     */
    @Transactional
    public void deleteYkTjcbBatch(List<String> ykTjcbList) {
        for(String id : ykTjcbList) {
            deleteYkTjcb(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    public YkTjcb getYkTjcb(Integer id) {

        return ykTjcbDao.getYkTjcbById(id);
    }
}